package com.orange.api;

import server.IHandleSessionManager;
import server.IHandlerRegister;
import common.DBHelper;
import db.Connector;

public class ApiRegister
{

    Connector core;
    final static String CORE_DATABASE = "core";

    private ApiRegister()
    {
        super();
        this.core = DBHelper.getConnector(CORE_DATABASE);
    }

    private static ApiRegister instance;

    public static ApiRegister getIntance()
    {
        if (null == instance)
        {
            instance = new ApiRegister();
        }
        return instance;
    }

    @SuppressWarnings("unchecked")
    public void register(IHandlerRegister server) throws Exception
    {
        server.register(new HelloWorld());
        server.register(new FeatureHandler());
        if (server instanceof IHandleSessionManager)
        {
            SessionHandler sessionHandler = new SessionHandler();
            server.register(sessionHandler);
            sessionHandler.setController(((IHandleSessionManager<String, Long, UserSession>) server).getSessionManager());
        }
        server.register(new PageHandler());
    }

    public Connector getCore()
    {
        return core;
    }
}
